package com.wink_172.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup
import com.wink_172.commons.R
import com.wink_172.commons.databinding.ActivityBlurBinding
import com.wink_172.library.activity.SmartActivity
import com.wink_172.library.adapter.HomeListAdapter
import com.wink_172.library.model.BaseDataItem
import com.wink_172.library.model.Constants
import com.wink_172.library.model.json.ImageData
import com.wink_172.library.utils.CommonUtils
import java.util.*

/**
 * 模糊控件 请注意主题样式不能为白色
 * android:theme="@style/AppTheme.Activity"
 */
class BlurActivity : SmartActivity() {
    lateinit var binding: ActivityBlurBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_blur)

        initView()
        init()
    }

    private fun init() {
//        ImageView imageView = new ImageView(this);
//        imageView.setLayoutParams(new ViewGroup.LayoutParams(150, 150));
//        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        x.image().bind(imageView,CommonUtils.getRandomImageUrl());
//        ((RealtimeBlurView) binding.singleView).bindView(imageView);
        val homeListAdapter = binding!!.listView.adapter as HomeListAdapter?
        val list: MutableList<Any> = ArrayList()
        for (i in 0..99) {
            val baseDataItem = BaseDataItem(i, Constants.List_Enum.选择图片列表.ordinal)
            baseDataItem.callback = object : HomeListAdapter.BaseViewsHolder.ICallback {
                override fun postObject(event: Int, vararg args: Any?) {}
            }
            val imageData = ImageData()
            imageData.web_url = CommonUtils.randomImageUrl
            baseDataItem.setObjectData(imageData)
            list.add(baseDataItem)
        }
        homeListAdapter!!.swapContent(list)
        homeListAdapter.notifyDataSetChanged()


//        x.task().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                int w = ((RealtimeBlurView) binding.singleView).getMeasuredWidth();
//                int h = ((RealtimeBlurView) binding.singleView).getMeasuredHeight();
//                Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
//                ImageUtil.saveBitmapFile3(bitmap, Constants.savePath + "blur.jpg");
//                CommonUtils.showToast("模糊图片已保存");
//            }
//        },2000);
    }

    private fun initView() {
        binding!!.listView.init(null, true)
        val gridLayoutManager = GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false)
        gridLayoutManager.spanSizeLookup = object : SpanSizeLookup() {
            override fun getSpanSize(position: Int): Int {
//                if (position < 7 || position > 14) {
//                    return 3;
//                }
                return 1
            }
        }
        binding!!.listView.layoutManager = gridLayoutManager
    }

    companion object {
        @JvmStatic
        fun startActivity(context: Context, vararg args: Any?) {
            val intent = Intent(context, BlurActivity::class.java)

            //intent.putExtra(Constants.PARAM_DATA1, (String) args[0]);
            context.startActivity(intent)
        }
    }
}